package com.gst.cloudygovernance.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.amap.api.services.core.PoiItem;
import com.gst.cloudygovernance.R;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;


public class SearchResultAdapter extends BaseAdapter {


    private ArrayList<PoiItem> poiItems;
    private Context context;

    public SearchResultAdapter(Context context, ArrayList<PoiItem> poiItems) {
        this.context = context;
        this.poiItems = poiItems;
    }

    @Override
    public int getCount() {
        return poiItems == null ? 0 : poiItems.size();
    }

    @Override
    public Object getItem(int position) {
        return poiItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.view_holder_result, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        PoiItem poiItem = poiItems.get(position);
        viewHolder.textTitle.setText(poiItem.getCityName());
        viewHolder.textTitleSub.setText(poiItem.toString());
//        LogUtil.e(poiItems.size()+"size");
        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.text_title)
        TextView textTitle;
        @Bind(R.id.text_title_sub)
        TextView textTitleSub;
        @Bind(R.id.image_check)
        ImageView imageCheck;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
